﻿namespace PageTypeBuilderUI
{
    using System.Web.Hosting;
    using PageTypeBuilder.UI;

    internal class ResourcePathProvider : VirtualPathProvider
    {
        private readonly string _virtualPath;
        private readonly string _resourceName;
        private readonly bool _physicalResource;
        public ResourcePathProvider(string virtualPath, string resourceName, bool physicalResource)
        {
            _virtualPath = virtualPath;
            _resourceName = resourceName;
            _physicalResource = physicalResource;
        }
        public override bool FileExists(string virtualPath)
        {
            return string.Compare(virtualPath, _virtualPath, true) == 0 || Previous.FileExists(virtualPath);
        }
        public override VirtualFile GetFile(string virtualPath)
        {
            if (string.Compare(virtualPath, _virtualPath, true) != 0)
                return Previous.GetFile(virtualPath);

            return new ResourceVirtualFile(_virtualPath, _resourceName, _physicalResource);
        }
    }
}
